{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "import sys\n",
    "sys.path.append(\"../../../teddy-cup\")\n",
    "from Utils.utils import *\n",
    "HelloWorld()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [],
   "source": [
    "Job_ = pd.read_csv(\"../../Data/ProcessData/Job.csv\")\n",
    "JobDetail_ = pd.read_csv(\"../../Data/ProcessData/JobDetail.csv\")\n",
    "Company_ = pd.read_csv(\"../../Data/ProcessData/CompanyDetail.csv\")\n",
    "People_ = pd.read_csv(\"../../Data/ProcessData/People.csv\")\n",
    "PeopleDetail_ = pd.read_csv(\"../../Data/ProcessData/PeopleDetail.csv\")\n",
    "Job = Job_.merge(JobDetail_).merge(Company_)                                    # 直接合并，防止后续ID的顺序变得混乱\n",
    "People = People_.merge(PeopleDetail_)                                           # 直接合并，防止后续ID的顺序变得混乱"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [],
   "source": [
    "People;"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1.等级匹配"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.学历匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [],
   "source": [
    "job_edu = Job[[\"jobId\",'educationalRequirements']]\n",
    "people_edu = People[[\"resumeId\",'degree']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "本科    1228\n",
      "大专     271\n",
      "硕士      52\n",
      "技工      11\n",
      "不限       9\n",
      "博士       4\n",
      "Name: educationalRequirements, dtype: int64\n",
      "本科    112\n",
      "硕士      4\n",
      "大专      2\n",
      "博士      1\n",
      "Name: degree, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "print(job_edu['educationalRequirements'].value_counts()),print(people_edu['degree'].value_counts())\n",
    "# 缺失值用众数进行填充\n",
    "people_edu['degree'] = people_edu['degree'].fillna(\"本科\")\n",
    "educationalRequirementsDic = {\n",
    "    \"博士\":5,\"硕士\":4,\"本科\":3,\"大专\":2,\"技工\":1,\"不限\":0,\n",
    "}\n",
    "job_edu['educationalRequirements'] = job_edu['educationalRequirements'].map(educationalRequirementsDic)\n",
    "people_edu['degree'] = people_edu['degree'].map(educationalRequirementsDic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(3    1228\n",
       " 2     271\n",
       " 4      52\n",
       " 1      11\n",
       " 0       9\n",
       " 5       4\n",
       " Name: educationalRequirements, dtype: int64,\n",
       " 3    8274\n",
       " 4       4\n",
       " 2       2\n",
       " 5       1\n",
       " Name: degree, dtype: int64)"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_edu['educationalRequirements'].value_counts(),people_edu['degree'].value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>educationalRequirements</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>125</th>\n",
       "      <td>1554023803397472256</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779</th>\n",
       "      <td>1482194903424434207</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1302</th>\n",
       "      <td>1482188020965834754</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1303</th>\n",
       "      <td>1482185488755458056</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId  educationalRequirements\n",
       "125   1554023803397472256                        5\n",
       "779   1482194903424434207                        5\n",
       "1302  1482188020965834754                        5\n",
       "1303  1482185488755458056                        5"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_edu[job_edu.educationalRequirements==5]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "匹配规则设置如下：\n",
    "\n",
    "+ **职位**设置的**学历**如果大于**求职者**的**学历**，则求职者不会出现在该职位的推荐上\n",
    "\n",
    "+ 定义匹配满意度如下：\n",
    "\n",
    "$$\n",
    "DegreenSim(r,j) =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,                    & q = 0\t\t\t\t\t\\\\\n",
    "\t0.8,\t\t\t\t\t& q = 1\t\t\t\t\t\\\\\n",
    "     0.6,\t\t\t\t& q=2 \t\t\t\t\t\\\\\n",
    "     0.4,\t\t\t\t& q = 3   \t\t\t\t\\\\\n",
    "     0.2,\t\t\t\t& q = 4  \t\t\t\t\\\\\n",
    "     0.1,\t\t\t\t& q = 5                 \\\\ \n",
    "     -inf ,               & job_{degree} > people_{degree} \n",
    "\\end{array}\n",
    "\\right.\n",
    "$$\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [],
   "source": [
    "A_edu = job_edu['educationalRequirements'].values\n",
    "B_edu = np.tile(people_edu['degree'],(len(job_edu),1))\n",
    "B_edu = AltB_axis1(B_edu,A_edu,-1)                               # 实现匹配规则1，先设置为-1，最后统一改成-inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_edu = AsubstractB(B_edu,A_edu,ignore=True,value=-1)             # 实现匹配规则2\n",
    "res_edu = res_edu.astype(float)\n",
    "res_edu"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 验证结果是否正确\n",
    "# temp = list(people_edu['degree'].copy(True))\n",
    "\n",
    "# job_edu_num = 3\n",
    "# for i in range(len(temp)):\n",
    "#     if temp[i] < job_edu_num:\n",
    "#         temp[i] = -1\n",
    "#     else:\n",
    "#         temp[i] -= job_edu_num\n",
    "# temp == list(res_exp[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_edu[res_edu==5] = 0.1\n",
    "res_edu[res_edu==4] = 0.2\n",
    "res_edu[res_edu==3] = 0.4\n",
    "res_edu[res_edu==2] = 0.6\n",
    "res_edu[res_edu==1] = 0.8\n",
    "res_edu[res_edu==0] = 1\n",
    "res_edu[res_edu == -1] = -np.inf\n",
    "res_edu"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.Exp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3     517\n",
      "0     471\n",
      "1     403\n",
      "5     175\n",
      "10      6\n",
      "7       3\n",
      "Name: exp, dtype: int64\n",
      "0     8243\n",
      "1       18\n",
      "4        6\n",
      "3        6\n",
      "10       4\n",
      "2        2\n",
      "6        1\n",
      "5        1\n",
      "Name: exp, dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(None, None)"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_exp = Job[['jobId',\"exp\"]]\n",
    "people_exp = People[[\"resumeId\",\"exp\"]]\n",
    "print(job_exp['exp'].value_counts()),print(people_exp['exp'].value_counts())"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将经验划分为：0-1、2-3、4-5、6以上4个区间，做出如下规则：\n",
    "\n",
    "<!-- + 按照未未对经验划分区间的数据进行分析：如果工作所需经验大于求职者的经验，那么求职求职满意度为-1，-1代表不会进行推荐 -->\n",
    "\n",
    "+ 划分完之后，按照划分区间后的数据进行分析：根据所属区间的距离进行划分，此时求职者的经验\n",
    "\n",
    "$$\n",
    "ExpSim(r,j) =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,     \t\t& abs(q) = 0\t\t\t\t\\\\\n",
    "    0.7,\t\t& abs(q) = 1  \\\\\n",
    "    0.4,\t\t& abs(q) = 2 \\\\\n",
    "    0.1\t\t\t& abs(q) = 3    \\\\\n",
    "    -np.inf     & job_{exp}>people_{exp}\n",
    "\\end{array}\n",
    "\\right.\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [],
   "source": [
    "EXPdic = {0:0,1:0,2:1,3:1,4:2,5:2,6:3,7:3,8:3,9:3,10:3}\n",
    "job_exp['exp2'] = job_exp['exp']\n",
    "job_exp['exp2'] = job_exp['exp2'].map(EXPdic)\n",
    "people_exp['exp2'] = people_exp['exp']\n",
    "people_exp['exp2'] = people_exp['exp2'].map(EXPdic)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [],
   "source": [
    "A_exp = job_exp['exp2'].values\n",
    "B_exp  = np.tile(people_exp['exp2'].values, (len(job_exp), 1))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "B_exp = AltB_axis1(B_exp,A_exp,-1)                               # 实现匹配规则1，先设置为-1，最后统一改成-inf"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       ...,\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.],\n",
       "       [0., 0., 0., ..., 0., 0., 0.]])"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_exp  = AsubstractB(B_exp , A_exp, ignore=True,value=-1)\n",
    "res_exp = res_exp.astype(float)\n",
    "res_exp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>exp</th>\n",
       "      <th>exp2</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>156</th>\n",
       "      <td>1531570545265606656</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>157</th>\n",
       "      <td>1531566491487567874</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>159</th>\n",
       "      <td>1531566491487567872</td>\n",
       "      <td>7</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>334</th>\n",
       "      <td>1482185263353561092</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>474</th>\n",
       "      <td>1482196148415496198</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>489</th>\n",
       "      <td>1482196087983964186</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>807</th>\n",
       "      <td>1482194903420239872</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1112</th>\n",
       "      <td>1482192311990484998</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1193</th>\n",
       "      <td>1482192055261331461</td>\n",
       "      <td>10</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId  exp  exp2\n",
       "156   1531570545265606656    7     3\n",
       "157   1531566491487567874    7     3\n",
       "159   1531566491487567872    7     3\n",
       "334   1482185263353561092   10     3\n",
       "474   1482196148415496198   10     3\n",
       "489   1482196087983964186   10     3\n",
       "807   1482194903420239872   10     3\n",
       "1112  1482192311990484998   10     3\n",
       "1193  1482192055261331461   10     3"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_exp[job_exp.exp2==3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 检测结果正确性\n",
    "# temp = list(people_exp['exp2'].copy(True))\n",
    "\n",
    "# def calculateOneLine(a,b,c):\n",
    "#     for i in range(len(b)):\n",
    "#         b[i] -= a\n",
    "#     return b==list(res_exp[c])\n",
    "\n",
    "# calculateOneLine(int(job_exp.loc[1446].exp2),temp,1446)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_exp[res_exp == 3.] = 0.1\n",
    "# res_exp[res_exp == -3.] = 0.1\n",
    "\n",
    "res_exp[res_exp == 2.] = 0.4\n",
    "# res_exp[res_exp == -2.] = 0.4\n",
    "\n",
    "res_exp[res_exp == 1.] = 0.7\n",
    "# res_exp[res_exp == -1.] = 0.7\n",
    "\n",
    "res_exp[res_exp == 0.] = 1\n",
    "res_exp[res_exp == -1.] = -np.inf\n",
    "res_exp"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.薪资计算匹配度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [],
   "source": [
    "job_salary = Job[[\"jobId\",'averageSalary']]\n",
    "people_salary = People[[\"resumeId\",\"averageSalary\"]]\n",
    "job_salary[\"salary_degree\"] = job_salary['averageSalary']\n",
    "people_salary['salary_degree'] = people_salary['averageSalary']\n",
    "\n",
    "def SalaryDic(x):\n",
    "    if x<3000:\n",
    "        return 0\n",
    "    if 3000<=x<6000:\n",
    "        return 1\n",
    "    if 6000<=x<10000:\n",
    "        return 2\n",
    "    if 10000<=x<25000:\n",
    "        return 3\n",
    "    if x>=25000:\n",
    "        return 4\n",
    "job_salary['salary_degree'] = job_salary['salary_degree'].map(SalaryDic)\n",
    "people_salary['salary_degree'] = people_salary['salary_degree'].map(SalaryDic)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "匹配计算规则：\n",
    "\n",
    "+ 根据前期对国民薪资水平的调研将月薪划分为 5 个区间：3000 元以下、 3000-6000 元、6000-10000 元、10000-25000 元、25000 元以 上。根据求职者的期望薪资所处的水平处在的区间进行划分。定义如下：\n",
    "\n",
    "$$\n",
    "SalarySim(r,j) =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,                    \t\t& abs(q)=0 \t\t\t\t\t\t\t\\\\\n",
    "    0.7\t\t\t\t\t\t\t& abs(q)=1\t\t\t\t\t\t\t\\\\\n",
    "    0.4,     \t\t\t\t\t& abs(q)=2\t\t\t\t\t\t\t\t\t\\\\\n",
    "    0.1                         & abs(q) = 3                \\\\\n",
    "    -np.inf\t\t\t\t\t\t\t& abs(q)=4\t\t\t\t\t\t\t\\\\\n",
    "\\end{array}\n",
    "\\right.\n",
    "$$\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [],
   "source": [
    "A_salary = job_salary['salary_degree'].values\n",
    "B_salary  = np.tile(people_salary['salary_degree'].values, (len(Job), 1))\n",
    "A_salary  = AsubstractB(B_salary ,A_salary)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 检测结果正确性\n",
    "temp = list(people_salary['salary_degree'].copy(True))\n",
    "\n",
    "def calculateOneLine(a,b,c):\n",
    "    for i in range(len(b)):\n",
    "        b[i] -= a\n",
    "    return b==list(A_salary[c])\n",
    "calculateOneLine(int(job_salary.loc[879].salary_degree),temp,879)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 概率映射\n",
    "A_salary = A_salary.astype(float)\n",
    "\n",
    "A_salary [A_salary ==1] = 0.7\n",
    "A_salary [A_salary ==-1] = 0.7\n",
    "A_salary [A_salary ==2] = 0.4\n",
    "A_salary [A_salary ==-2] = 0.4\n",
    "A_salary [A_salary ==3] = 0.1\n",
    "A_salary [A_salary ==-3] = 0.1\n",
    "A_salary [A_salary == 4] = -np.inf\n",
    "A_salary [A_salary ==-4] = -np.inf\n",
    "\n",
    "A_salary [A_salary ==0] = 1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       [1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       [1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       ...,\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7],\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7],\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7]])"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_salary = A_salary\n",
    "res_salary"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 4.省市匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1648527394191052801</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1648527394191052800</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1648165203084447745</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济宁市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1648165203084447744</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济宁市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1570</th>\n",
       "      <td>1462698431867912192</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1571</th>\n",
       "      <td>1461590578927108096</td>\n",
       "      <td>上海省</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1572</th>\n",
       "      <td>1461591923750993920</td>\n",
       "      <td>上海省</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573</th>\n",
       "      <td>1461593160642854912</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1574</th>\n",
       "      <td>1461595991152132096</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1575 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId province city\n",
       "0     1648527394191052802      广东省  深圳市\n",
       "1     1648527394191052801      广东省  深圳市\n",
       "2     1648527394191052800      广东省  深圳市\n",
       "3     1648165203084447745      山东省  济宁市\n",
       "4     1648165203084447744      山东省  济宁市\n",
       "...                   ...      ...  ...\n",
       "1570  1462698431867912192      广东省  深圳市\n",
       "1571  1461590578927108096      上海省  上海市\n",
       "1572  1461591923750993920      上海省  上海市\n",
       "1573  1461593160642854912      广东省  深圳市\n",
       "1574  1461595991152132096      广东省  广州市\n",
       "\n",
       "[1575 rows x 3 columns]"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_area = Job[[\"jobId\",\"province\",\"city\"]]\n",
    "job_area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1574625077318778880</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1573938917198135296</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1569987734318219264</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1569514123790778368</td>\n",
       "      <td>湖北省</td>\n",
       "      <td>武汉市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1562334736783900672</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8276</th>\n",
       "      <td>7539911466257411604</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8277</th>\n",
       "      <td>7539911474847346196</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8278</th>\n",
       "      <td>7539911483437280788</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8279</th>\n",
       "      <td>7539911492027215380</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8280</th>\n",
       "      <td>7539911500617149972</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8281 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 resumeId province city\n",
       "0     1574625077318778880      广东省  深圳市\n",
       "1     1573938917198135296      广东省  广州市\n",
       "2     1569987734318219264      广东省  广州市\n",
       "3     1569514123790778368      湖北省  武汉市\n",
       "4     1562334736783900672      广东省  广州市\n",
       "...                   ...      ...  ...\n",
       "8276  7539911466257411604      NaN  NaN\n",
       "8277  7539911474847346196      NaN  NaN\n",
       "8278  7539911483437280788      NaN  NaN\n",
       "8279  7539911492027215380      NaN  NaN\n",
       "8280  7539911500617149972      NaN  NaN\n",
       "\n",
       "[8281 rows x 3 columns]"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "people_area = People[[\"resumeId\",\"province\",'city']]\n",
    "def f3(x):\n",
    "    if x==\"天津市\":\n",
    "        return \"天津省\"\n",
    "    if x==\"上海市\":\n",
    "        return  \"上海省\"\n",
    "    if x==\"重庆市\":\n",
    "        return \"重庆省\"\n",
    "    if x== \"北京市\":\n",
    "        return \"北京省\"\n",
    "    return x\n",
    "people_area['province'] = people_area['province'].map(f3)\n",
    "people_area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(array(['广东省', '广东省', '广东省', ..., '上海省', '广东省', '广东省'], dtype=object),\n",
       " array([['广东省', '广东省', '广东省', ..., nan, nan, nan],\n",
       "        ['广东省', '广东省', '广东省', ..., nan, nan, nan],\n",
       "        ['广东省', '广东省', '广东省', ..., nan, nan, nan],\n",
       "        ...,\n",
       "        ['广东省', '广东省', '广东省', ..., nan, nan, nan],\n",
       "        ['广东省', '广东省', '广东省', ..., nan, nan, nan],\n",
       "        ['广东省', '广东省', '广东省', ..., nan, nan, nan]], dtype=object))"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A_province = job_area['province'].values\n",
    "B_province = np.tile(people_area['province'].values,(len(job_area),1))\n",
    "A_city = job_area['city'].values\n",
    "B_city = np.tile(people_area['city'].values, (len(job_area),1))\n",
    "A_province,B_province"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "匹配规则如下：\n",
    "\n",
    "$$\n",
    "AreaSim(r,j) =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,                    \t\t\t& 同省同市 \t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\\\n",
    "    0.5\t\t\t\t\t\t\t\t& 同省不同市\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\\\\\n",
    "    0,     \t\t\t\t\t\t& 不同省不同市\t\t\t\t\t\t\t\t\t\t\t\t\\\\\n",
    "\t\n",
    "\\end{array}\n",
    "\\right.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [],
   "source": [
    "res1 = AsameB(A_province,B_province)\n",
    "res2 = AsameB(A_city,B_city)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>province</th>\n",
       "      <th>city</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1648527394191052801</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1648527394191052800</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1648165203084447745</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济宁市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1648165203084447744</td>\n",
       "      <td>山东省</td>\n",
       "      <td>济宁市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1570</th>\n",
       "      <td>1462698431867912192</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1571</th>\n",
       "      <td>1461590578927108096</td>\n",
       "      <td>上海省</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1572</th>\n",
       "      <td>1461591923750993920</td>\n",
       "      <td>上海省</td>\n",
       "      <td>上海市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573</th>\n",
       "      <td>1461593160642854912</td>\n",
       "      <td>广东省</td>\n",
       "      <td>深圳市</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1574</th>\n",
       "      <td>1461595991152132096</td>\n",
       "      <td>广东省</td>\n",
       "      <td>广州市</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1575 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId province city\n",
       "0     1648527394191052802      广东省  深圳市\n",
       "1     1648527394191052801      广东省  深圳市\n",
       "2     1648527394191052800      广东省  深圳市\n",
       "3     1648165203084447745      山东省  济宁市\n",
       "4     1648165203084447744      山东省  济宁市\n",
       "...                   ...      ...  ...\n",
       "1570  1462698431867912192      广东省  深圳市\n",
       "1571  1461590578927108096      上海省  上海市\n",
       "1572  1461591923750993920      上海省  上海市\n",
       "1573  1461593160642854912      广东省  深圳市\n",
       "1574  1461595991152132096      广东省  广州市\n",
       "\n",
       "[1575 rows x 3 columns]"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "# # 测试：输入第i行，得到第i行对应省份；进行暴力匹配与res1中结果相同即可\n",
    "# test_array = []\n",
    "# for i in B_province[0]:\n",
    "#     if i==\"上海省\":\n",
    "#         test_array.append(1)\n",
    "#     else:\n",
    "#         test_array.append(0)\n",
    "        \n",
    "# test_array == list(res1[1571])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       ...,\n",
       "       [0. , 0. , 0. , ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [0.5, 1. , 1. , ..., 0. , 0. , 0. ]])"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_area = res1+res2\n",
    "res_area = res_area.astype(float)\n",
    "\n",
    "res_area[res_area==1] = 0.5                 # 同省不同市\n",
    "res_area[res_area==2] = 1                   # 同省同市\n",
    "res_area"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 5.全职或实习匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [],
   "source": [
    "job_willnature = Job[['jobId',\"willNature\"]]\n",
    "people_willnature = People[['resumeId',\"willNature\"]]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "缺失值采用众数进行填充\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [],
   "source": [
    "people_willnature['willNature'] = people_willnature['willNature'].fillna(\"全职\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1575, 8281)"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A_willnature = job_willnature['willNature'].values\n",
    "B_willnature = np.tile(people_willnature['willNature'].values,(len(job_willnature),1))\n",
    "B_willnature.shape"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "匹配规则：\n",
    "\n",
    "$$\n",
    "willnatureSim =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,                    \t\t\t& people_{willnature}=job_{willnature}\t\t\t\t\t\t\t\t\t\t\t\t\\\\\t\n",
    "    -inf\t\t\t\t\t\t\t\t& people_{willnature}\\not =job_{willnature}\t\n",
    "\\end{array}\n",
    "\\right.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_willnature = AsameB(A_willnature,B_willnature)\n",
    "res_willnature = res_willnature.astype(float)\n",
    "res_willnature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>jobId</th>\n",
       "      <th>willNature</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1648527394191052802</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1648527394191052801</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1648527394191052800</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1648165203084447745</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1648165203084447744</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1570</th>\n",
       "      <td>1462698431867912192</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1571</th>\n",
       "      <td>1461590578927108096</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1572</th>\n",
       "      <td>1461591923750993920</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1573</th>\n",
       "      <td>1461593160642854912</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1574</th>\n",
       "      <td>1461595991152132096</td>\n",
       "      <td>全职</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1575 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                    jobId willNature\n",
       "0     1648527394191052802         全职\n",
       "1     1648527394191052801         全职\n",
       "2     1648527394191052800         全职\n",
       "3     1648165203084447745         全职\n",
       "4     1648165203084447744         全职\n",
       "...                   ...        ...\n",
       "1570  1462698431867912192         全职\n",
       "1571  1461590578927108096         全职\n",
       "1572  1461591923750993920         全职\n",
       "1573  1461593160642854912         全职\n",
       "1574  1461595991152132096         全职\n",
       "\n",
       "[1575 rows x 2 columns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "job_willnature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 测试结果正确性\n",
    "test_array = []\n",
    "for i in B_willnature[0]:\n",
    "    if i==\"实习\":\n",
    "        test_array.append(1)\n",
    "    else:\n",
    "        test_array.append(0)\n",
    "        \n",
    "test_array == list(res_willnature[1513])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_willnature[res_willnature==0] = -np.inf\n",
    "res_willnature"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 6.岗位匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [],
   "source": [
    "job_pos = Job[[\"jobId\",'positionName2']]\n",
    "people_pos = People[[\"resumeId\",\"expectPosition2\"]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>resumeId</th>\n",
       "      <th>expectPosition2</th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1574625077318778880</td>\n",
       "      <td>数据分析类|大数据开发类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>大数据开发类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1573938917198135296</td>\n",
       "      <td>大数据开发类</td>\n",
       "      <td>大数据开发类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1569987734318219264</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1569514123790778368</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1562334736783900672</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8276</th>\n",
       "      <td>7539911466257411604</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8277</th>\n",
       "      <td>7539911474847346196</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8278</th>\n",
       "      <td>7539911483437280788</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8279</th>\n",
       "      <td>7539911492027215380</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8280</th>\n",
       "      <td>7539911500617149972</td>\n",
       "      <td>数据分析类|人工智能类</td>\n",
       "      <td>数据分析类</td>\n",
       "      <td>人工智能类</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8281 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                 resumeId expectPosition2       0       1     2     3\n",
       "0     1574625077318778880    数据分析类|大数据开发类   数据分析类  大数据开发类  None  None\n",
       "1     1573938917198135296          大数据开发类  大数据开发类    None  None  None\n",
       "2     1569987734318219264     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "3     1569514123790778368           数据分析类   数据分析类    None  None  None\n",
       "4     1562334736783900672     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "...                   ...             ...     ...     ...   ...   ...\n",
       "8276  7539911466257411604     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "8277  7539911474847346196     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "8278  7539911483437280788     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "8279  7539911492027215380     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "8280  7539911500617149972     数据分析类|人工智能类   数据分析类   人工智能类  None  None\n",
       "\n",
       "[8281 rows x 6 columns]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "split_df = people_pos['expectPosition2'].str.split('|', expand=True)\n",
    "people_pos = pd.concat([people_pos, split_df], axis=1)\n",
    "people_pos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [],
   "source": [
    "people_pos[0] = people_pos[0].fillna(\"abcd\")\n",
    "people_pos[1] = people_pos[1].fillna(\"abcd\")\n",
    "people_pos[2] = people_pos[2].fillna(\"abcd\")\n",
    "people_pos[3] = people_pos[3].fillna(\"abcd\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "匹配规则：\n",
    "一个人的期望职业有多个，因此job的职位和人的每个期望的所有职位进行匹配，能匹配上就是1，否则就是0；\n",
    "\n",
    "因此只需要对所有的矩阵进行 **或运算** 就能完成任务\n",
    "\n",
    "$$\n",
    "PositionSim =\n",
    " \\left \\{\n",
    "\\begin{array}{ll}\n",
    "    1,                    \t\t\t    & p_{position}=j_{position}\t\t\t\t\t\t\t\t\t\t\t\t\\\\\t\n",
    "\t-inf \t\t\t\t\t\t\t\t& p_{position} \\not=j_{position}\n",
    " \\end{array}\n",
    "\\right.\n",
    "\n",
    "$$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "A_pos = job_pos['positionName2'].values\n",
    "B_pos0 = np.tile(people_pos[0].values,(len(job_pos),1))\n",
    "B_pos1 = np.tile(people_pos[1].values,(len(job_pos),1))\n",
    "B_pos2 = np.tile(people_pos[2].values,(len(job_pos),1))\n",
    "B_pos3 = np.tile(people_pos[3].values,(len(job_pos),1))\n",
    "\n",
    "res_pos1 = AsameB(A_pos,B_pos0)\n",
    "res_pos2 = AsameB(A_pos,B_pos1)\n",
    "res_pos3 = AsameB(A_pos,B_pos2)\n",
    "res_pos4 = AsameB(A_pos,B_pos3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0, 0, 0, ..., 0, 0, 0],\n",
       "       [1, 0, 1, ..., 1, 1, 1],\n",
       "       [1, 0, 1, ..., 1, 1, 1],\n",
       "       ...,\n",
       "       [1, 0, 1, ..., 1, 1, 1],\n",
       "       [0, 1, 0, ..., 0, 0, 0],\n",
       "       [1, 0, 1, ..., 1, 1, 1]])"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_pos1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0., 0., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 1., ..., 1., 1., 1.],\n",
       "       [1., 0., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 0., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 0., ..., 0., 0., 0.],\n",
       "       [1., 0., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_pos = np.logical_or(np.logical_or(res_pos1,res_pos2),np.logical_or(res_pos3,res_pos4))\n",
    "res_pos = res_pos.astype(int)\n",
    "res_pos = res_pos.astype(float)\n",
    "res_pos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "temp = people_pos['expectPosition2'].copy(deep=True).values\n",
    "aa = []\n",
    "\n",
    "job_pos_str = \"其他类\"\n",
    "for i in range(len(temp)):\n",
    "    if job_pos_str in temp[i]:\n",
    "        temp[i] = 1\n",
    "    else:\n",
    "        temp[i] = 0\n",
    "list(temp) == list(res_pos[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-inf, -inf, -inf, ..., -inf, -inf, -inf],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       ...,\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       [  1.,   1., -inf, ..., -inf, -inf, -inf],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.]])"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_pos[res_pos==0] = -np.inf\n",
    "res_pos"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2.进行匹配"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_edu\",res_edu)\n",
    "res_edu\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_exp\",res_exp)\n",
    "res_exp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       [1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       [1. , 1. , 1. , ..., 0.4, 0.4, 0.4],\n",
       "       ...,\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7],\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7],\n",
       "       [0.7, 0.7, 0.7, ..., 0.7, 0.7, 0.7]])"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_salary\",res_salary)\n",
    "res_salary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       ...,\n",
       "       [0. , 0. , 0. , ..., 0. , 0. , 0. ],\n",
       "       [1. , 0.5, 0.5, ..., 0. , 0. , 0. ],\n",
       "       [0.5, 1. , 1. , ..., 0. , 0. , 0. ]])"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_area\",res_area)\n",
    "res_area"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       ...,\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.],\n",
       "       [1., 1., 1., ..., 1., 1., 1.]])"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_willnature\",res_willnature)\n",
    "res_willnature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-inf, -inf, -inf, ..., -inf, -inf, -inf],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       ...,\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.],\n",
       "       [  1.,   1., -inf, ..., -inf, -inf, -inf],\n",
       "       [  1., -inf,   1., ...,   1.,   1.,   1.]])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.savez(\"res_pos\",res_pos)\n",
    "res_pos"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[      -inf,       -inf,       -inf, ...,       -inf,       -inf,\n",
       "              -inf],\n",
       "       [1.        ,       -inf, 0.91666667, ..., 0.73333333, 0.73333333,\n",
       "        0.73333333],\n",
       "       [1.        ,       -inf, 0.91666667, ..., 0.73333333, 0.73333333,\n",
       "        0.73333333],\n",
       "       ...,\n",
       "       [0.78333333,       -inf, 0.78333333, ..., 0.78333333, 0.78333333,\n",
       "        0.78333333],\n",
       "       [0.95      , 0.86666667,       -inf, ...,       -inf,       -inf,\n",
       "              -inf],\n",
       "       [0.86666667,       -inf, 0.95      , ..., 0.78333333, 0.78333333,\n",
       "        0.78333333]])"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "res_structure_feature = (res_salary+res_area+res_edu+res_exp+res_pos+res_willnature) /6\n",
    "np.savez(\"res_res_structure_feature\",res_structure_feature)\n",
    "res_structure_feature"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.1"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
